package com.global.model;

import java.io.Serializable;
import javax.persistence.*;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;


/**
 * The persistent class for the ZLY_PT_SYS_PARA database table.
 * @author zly601436 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate=true)
@Table(name = "ZLY_PT_SYS_PARA")
@SequenceGenerator(name = "ZLY_PT_SYS_PARA_ID_GENERATOR", sequenceName = "ZLY_PT_SYS_PARA_ID_SEQ", initialValue=100, allocationSize=1)
@NamedQueries({
        @NamedQuery(
                name = "findSystemParameterByName",
                query = "select s from SystemParameter s where upper(s.name) = :uniqueName "
        )
})
public class SystemParameter extends BaseObject implements Serializable {

	private static final long serialVersionUID = -573635424933213386L;
	
	private long id;
	private String name;
	private String description;
	
	private String value;
	private SystemType dataType;
	
    /**
     * 定义操作人、操作时间
     */
    private Who who;


	public SystemParameter() {
	}

	@Id	
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ZLY_PT_SYS_PARA_ID_GENERATOR")
	@SearchableId
	public Long getId() {
		return this.id;
	}
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 获取参数名称
	 * @return String
	 */
	@Column(nullable = false, length=128)
	@SearchableProperty
	public String getName() {
		return this.name;
	}
	/**
	 * 设置参数名称
	 * @param name
	 */
	public void setName(String name) {
		this.name = StringUtils.isBlank(name) ? "" : name.trim().toUpperCase();
	}

	/**
	 * 返回参数值
	 * @return String
	 */
	@Column(nullable = false, length=512)
	public String getValue() {
		return this.value;
	}
	/**
	 * 设置参数值
	 * @param value
	 */
	public void setValue(String value) {
		this.value = StringUtils.isNotBlank(value) ? value.trim() : "";
	}
	
	/**
	 * 返回参数的描述信息
	 * @return String
	 */
	@Column(nullable = false, length=1024)
	@SearchableProperty
	public String getDescription() {
		return this.description;
	}
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * 返回参数的数据类型
	 * @return
	 */
	// bi-directional many-to-one association to ParameterType
	@ManyToOne
	@JoinColumn(name = "DATATYPE_ID", nullable = false)
	public SystemType getDataType() {
		return this.dataType;
	}
	/**
	 * 设置参数的数据类型
	 * @param dataType
	 */
	public void setDataType(SystemType dataType) {
		this.dataType = dataType;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Who getWho() {
		return who;
	}
	/**
     * {@inheritDoc}
     */
	@Override
	public void setWho(Who who) {
		this.who = who;
	}

	@Override
	public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
        .append("name", this.name)
        .append("description", this.description);

        return sb.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		
		SystemParameter other = (SystemParameter) obj;
		
		if (id != other.id){
			if (name == null) {
				if (other.name != null)
					return false;
			} else if (!name.equalsIgnoreCase(other.name)){
				return false;
			}
		}
		
		return true;
	}
}